<?php

class Student {
    public $name;
    public $addr="地址不祥";
    
}

$stu = new Student();
print_r($stu);

$stu->name="tom";
echo "姓名".$stu->name."\n";
$sss = "sdsd"."sdsdsdsdsd\n";
echo $sss;


class Animal {
    private $type = "动物";
    public function show() {
        echo "show";
    }

    public function test() {
        echo "test";
    }

    public function showType() {
        echo $this->type;
    }
}

// 子类不能够访问父类的私有属性 子类覆盖私有属性导致对象有两个一样的属性 但是覆盖protected则是真的覆盖
class Dog extends Animal {

    public function show($num) {
        echo $num."\n";
    }

    // protected function test() { 报错
    //     echo "hahhahah";
    // }

    public function sss() {
        // echo $this->type;
    }

    // public function sss($num) {  不支持重载
        
    // }
}


$dog = new Dog();
$dog->show(23);
$dog->sss();

// 静态方法
class Person {
    public static $add = "北京";
    static public function show() {
        echo "这是一个静态方法\n";
    }
}

echo Person::$add."\n";
Person::show();


// final 修饰的方法不能被继承和重写

// abstract 抽象方法

abstract class Person3 {
    public abstract function setinfo();
    public function getinfo() {
        echo "获取信息\n";
    }
}

class Students extends Person3 {
    public $name = "张三";
    public function setinfo() {
        echo "实现抽象方法\n";
    }
}

$stu = new Students();

// $p = new Person3(); 错误
$stu->setinfo();
$stu->getinfo();
echo $stu->name ."\n";
// echo $stu->$name ."\n";  静态成员才加$

// self 当前类的类型
class SelfTest {
    private static $name = "张三2222";
    private $age = 23;
    public function test() {
        echo self::$name ."\n";
        // echo self::$age ."\n"; PHP Fatal error:  Uncaught Error: Access to undeclared static property: SelfTest::$age
    }
}

$test = new SelfTest();
$test->test();

// static 当前对象所属的类额外
class Personx {
    public static $type = "额外";
    public function show1() {
        echo static::$type ."\n";
    }
}

$obj = new Personx();
$obj->show1();